﻿using System.Windows;
using System.Windows.Controls;
using System.Collections;
using Kiva7.Controls;
using Kiva7.DataRequests;
using Kiva7.DataClasses;

namespace Kiva7.Pages
{
    public partial class LoansAndDetailControl : BaseUserControl
    {
        public LoansAndDetailControl()
        {
            InitializeComponent();
        }

        public void SetBindingList(IEnumerable itemsSource)
        {
            lbxLoans.ItemsSource = itemsSource;
        }

        LoanDetailRequest _request;
        private void BaseUserControl_Loaded(object sender, RoutedEventArgs e)
        {
            _request = new LoanDetailRequest();
            loanDetail.DataContext = _request;
            GetLoan();
        }

        private void lbxLoans_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            GetLoan();
        }

        private void GetLoan()
        {
            Loan loan = lbxLoans.SelectedItem as Loan;
            if (loan != null)
            {
                _request.GetLoan(loan.Id);
            }
        }
    }
}
